local args = {key=KEYS[1],min=ARGV[1],max=ARGV[2],count=ARGV[3]}
local records = redis.call('ZRANGEBYSCORE',args.key,args.min,args.max,'LIMIT',0,args.count)
local result={}
for i,r in pairs(records) do
	table.insert(result,r)
	redis.call('ZREM',args.key,r)
end
return result